package com.jtyoui.hdfs;

import java.io.IOException;

import com.jtyoui.path.Address;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

public class GetSubdirectory {

    private static void getFile(Path path, FileSystem fs) throws IOException {
        FileStatus[] fileStatus = fs.listStatus(path);
        for (FileStatus f : fileStatus) {
            if (f.isDirectory()) {
                Path p = new Path(f.getPath().toString());
                getFile(p, fs);
            } else {
                System.out.println(f.getPath().toString());
            }
        }
    }

    public static void main(String[] args) throws IOException {
        System.setProperty("HADOOP_USER_NAME", "hadoop");
        Configuration conf = new Configuration();
        FileSystem fs = FileSystem.get(conf);
        Path path = new Path(Address.HADOOP_PATH.toString());
        getFile(path, fs);
        fs.close();
    }
}
